<template>
	<el-main>
		<el-form :model="FormData" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="0px">
			<el-form-item label="" prop="list">
				<sc-form-table ref="table" v-model="FormData.itemList" :addTemplate="addTemplate" drag-sort
					placeholder="暂无数据">
					<el-table-column prop="type" label="区域类型名称" min-width="180">
						<template #default="scope">
							<el-input v-model="scope.row.name" type="text" placeholder="区域类型名称"
								clearable></el-input>
						</template>
					</el-table-column>
				</sc-form-table>
			</el-form-item>
			<el-form-item label="">
				<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
			</el-form-item>
		</el-form>
	</el-main>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				showAMap: false,
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '查看'
				},
				visible: true,
				isSaveing: false,
				fileurlArr: [],
				//表单数据
				FormData: {
					itemList: [],
				},
				//验证规则
				rules: {
					name: [{
						required: true,
						message: '请选择所属门店'
					}],
					timeout: [{
						required: true,
						message: '请填写超时'
					}],
					demo: [{
						required: true,
						message: '请填写状态说明'
					}],

				},
				userInfo: {},
				addTemplate: {
					name: '',
					val: '',
				},
			}
		},
		created() {

		},
		mounted() {},
		methods: {
			//新增等级
			addItem() {
				if (this.itemList.length == 9) {
					this.$message('最多只能新增9级！')
				} else {
					this.itemList.push({
						name: []
					})
				}
			},
			// 删除等级
			deleteItem(item, index) {
				this.itemList.splice(index, 1)
			},
			//显示
			open(mode = 'add') {
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			async submit() {
				var valid = await this.$refs.dialogForm.validate().catch(() => {})
				if (!valid) {
					return false
				}
				this.isSaveing = true

				delete this.FormData.createByName
				console.log(this.FormData)

				const res = await this.$API.api.ptemp.save.post(this.FormData)
				this.isSaveing = false;
				if (res.code == 200) {
					this.$emit('success', this.FormData, this.mode)
					this.visible = false;
					this.$message.success("操作成功")
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					})
				}
			},
			//表单注入数据
			setData() {
				// this.FormData.id = data.id
				// this.FormData.demo = data.demo
				// this.FormData.name = data.name
				// this.FormData.timeout = data.timeout
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.FormData, data)
			}
		}
	}
</script>

<style>
</style>
